package com.dayu.finecomm.protocol.hd72;

import java.text.SimpleDateFormat;
import java.util.Date;

/***
 * HD72 公理类
 */
public abstract class HD72Convention {

	public static int gprsInterval(short type) {

		// (0,5,15,30,60,120);
		switch (type) {
		case 0:
			return 0 * 60 * 1000;
		case 1:
			return 5 * 60 * 1000;
		case 2:
			return 15 * 60 * 1000;
		case 3:
			return 30 * 60 * 1000;
		case 4:
			return 60 * 60 * 1000;
		case 5:
			return 120 * 60 * 1000;
		}

		return 0;
	}

	public static int interval(short type) {

		int nInterval = 0;

		switch (type) {
		case 0x31:
			nInterval = 15 * 60 * 1000;
			break;
		case 0x32:
			nInterval = 30 * 60 * 1000;
			break;
		case 0x33:
			nInterval = 60 * 60 * 1000;
			break;
		case 0x34:
			nInterval = 120 * 60 * 1000;
			break;
		case 0x35:
			nInterval = 240 * 60 * 1000;
			break;
		case 0x36:
			nInterval = 360 * 60 * 1000;
			break;
		case 0x37:
			nInterval = 720 * 60 * 1000;
			break;
		case 0x38:
			nInterval = 1440 * 60 * 1000;
			break;
		case 0x40:
			nInterval = 1 * 60 * 1000;
			break;
		case 0x41:
			nInterval = 5 * 60 * 1000;
			break;
		case 0x42:
			nInterval = 10 * 60 * 1000;
			break;
		case 0x43:
			nInterval = 1 * 60 * 1000;
			break;
		case 0x44:
			nInterval = 5 * 60 * 1000;
			break;
		case 0x45:
			nInterval = 10 * 60 * 1000;
			break;
		case 0x46:
			nInterval = 20 * 60 * 1000;
		}

		return nInterval;
	}

	/**
	 * DDDD协议的时间间隔
	 * 
	 * @param type
	 * @return
	 */
	public static int intervalDDDD(short type) {

		int nInterval = 0;

		switch (type) {
		case 0x31:
			nInterval = 15 * 60 * 1000;
			break;
		case 0x32:
			nInterval = 30 * 60 * 1000;
			break;
		case 0x33:
			nInterval = 60 * 60 * 1000;
			break;
		case 0x34:
			nInterval = 120 * 60 * 1000;
			break;
		case 0x35:
			nInterval = 240 * 60 * 1000;
			break;
		case 0x36:
			nInterval = 360 * 60 * 1000;
			break;
		case 0x37:
			nInterval = 720 * 60 * 1000;
			break;
		case 0x38:
			nInterval = 1440 * 60 * 1000;
			break;
		case 0x41:
			nInterval = 1 * 60 * 1000;
			break;
		case 0x42:
			nInterval = 5 * 60 * 1000;
			break;
		case 0x43:
			nInterval = 10 * 60 * 1000;
			break;
		}

		return nInterval;
	}

	/**
	 * ABCD协议的间隔
	 * 
	 * @param type
	 * @return
	 */
	public static int intervalABAB(short type) {

		int nInterval = 0;

		switch (type) {
		case 0x31:
			nInterval = 15 * 60 * 1000;
			break;
		case 0x32:
			nInterval = 30 * 60 * 1000;
			break;
		case 0x33:
			nInterval = 60 * 60 * 1000;
			break;
		case 0x34:
			nInterval = 120 * 60 * 1000;
			break;
		case 0x35:
			nInterval = 240 * 60 * 1000;
			break;
		case 0x36:
			nInterval = 360 * 60 * 1000;
			break;
		case 0x37:
			nInterval = 720 * 60 * 1000;
			break;
		case 0x38:
			nInterval = 1440 * 60 * 1000;
			break;
		case 0x41:
			nInterval = 15 * 1000;
			break;
		case 0x42:
			nInterval = 30 * 1000;
			break;
		case 0x43:
			nInterval = 1 * 60 * 1000;
			break;
		case 0x44:
			nInterval = 5 * 60 * 1000;
			break;
		case 0x45:
			nInterval = 10 * 60 * 1000;
			break;
		}

		return nInterval;
	}

	/**
	 * CCCC协议的时间间隔
	 * 
	 * @param type
	 * @return
	 */
	public static int intervalCCCC(short type) {

		int nInterval = 0;

		switch (type) {
		case 0x31:
			nInterval = 15 * 60 * 1000;
			break;
		case 0x32:
			nInterval = 30 * 60 * 1000;
			break;
		case 0x33:
			nInterval = 60 * 60 * 1000;
			break;
		case 0x34:
			nInterval = 120 * 60 * 1000;
			break;
		case 0x35:
			nInterval = 240 * 60 * 1000;
			break;
		case 0x36:
			nInterval = 360 * 60 * 1000;
			break;
		case 0x37:
			nInterval = 720 * 60 * 1000;
			break;
		case 0x38:
			nInterval = 1440 * 60 * 1000;
			break;
		case 0x41:
			nInterval = 1 * 60 * 1000;
			break;
		case 0x42:
			nInterval = 5 * 60 * 1000;
			break;
		case 0x43:
			nInterval = 10 * 60 * 1000;
			break;
		}

		return nInterval;
	}

	/**
	 * 数据上发间隔标识
	 * 
	 * @param interval
	 *            单位为分钟
	 * @return
	 */
	public static String dataInterval(int m) {

		String nInterval = "0";

		switch (m) {
		case 1:
			nInterval = "C";
			break;
		case 5:
			nInterval = "D";
			break;
		case 10:
			nInterval = "E";
			break;
		case 15:
			nInterval = "1";
			break;
		case 30:
			nInterval = "2";
			break;
		case 60:
			nInterval = "3";
			break;
		case 120:
			nInterval = "4";
			break;
		}

		return nInterval;
	}

	/***
	 * HD72校时指令
	 * 
	 * @return 666666#C：0410010830#
	 */
	public static String timing() {

		return timing(new Date());
	}

	public static String timing(long millis) {

		return timing(new Date(millis));
	}

	public static String timing(Date date) {

		return "666666#C:" + new SimpleDateFormat("yyMMddHHmm").format(date)
				+ "#";
	}

}
